<?php
declare (strict_types = 1);

namespace app\middleware;
use think\exception\ValidateException;
use app\validate\User as Abc;

class Check
{
    /**
     * 处理请求
     *
     * @param \think\Request $request
     * @param \Closure       $next
     * @return Response
     */
    public function handle($request, \Closure $next)
    {   
        //中间件调用验证器拦截验证
        try {
            validate(Abc::class)->check([
                'name' => input('name')
            ]);
        } catch (ValidateException $e) {
            // 验证失败 输出错误信息
            dump($e->getError());
            die();
        }
        if ($request->param('name') == 'think') {
            echo "中间件处理！<br>";
            return redirect('../../admin/total/middleWareProcess');
        }
        if ($request->param('name') == 'abc') {
            return json(['message' => '错误']);
        }
        var_dump('in middleware');

        return $next($request);
    }
}
